﻿using System.Web.Mvc;
using SlamCms.Common;
using SlamCms.Data;
using SlamCmsDemo.Data;
using SlamCmsDemo.Web.Core.Models;

namespace SlamCmsDemo.Web.Core
{
	public static class UrlHelperExtensions
	{
		public static string ContentItemDetails(this UrlHelper urlHelper, ContentItem contentItem)
		{
			return urlHelper.Action("Details", "ContentItem", new { contentType = contentItem.ContentTypeId, contentItemId = contentItem.ContentItemId, slug = contentItem.Slug });
		}

		public static string ContentItemDetails(this UrlHelper urlHelper, ContentListItem contentListItem)
		{
			return urlHelper.ContentItemDetails(contentListItem.ContentItem);
		}

		public static string ContentItemIcon(this UrlHelper urlHelper, ContentItem contentItem, string size = null)
		{
			var sizeString = size == null ? string.Empty : "_{0}".F(size);
			return urlHelper.Image("icons/{0}{1}.png".F(contentItem.ContentTypeId, sizeString)).ToHtmlString();
		}

		public static string DownloadFile(this UrlHelper urlHelper, Download contentItem)
		{
			return urlHelper.AdminRedirectorRelative("document", contentItem.PrimaryContentItemId, new { version = contentItem.IsDraft() ? "draft" : "live" });
		}
	}
}